<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function fn (msg, t) {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    resolve(msg);
                }, t);
            });
        }
        
        // const p = fn('hello world', 1000);
        // p.then((res) => {
        //     console.log(res);
        //     const p1 = fn('hi', 2000);
        //     p1.then((res) => {
        //         console.log(res);
        //     });
        // });
        
        // 一秒之后打印'hello world'，'hello world'打印2秒之后打印'hi'
        
        async function f1 () {
            const res = await fn('hello world', 1000);
            console.log(res);
            const res1 = await fn('hi', 2000);
            console.log(res1);
        }
        f1();
    </script>
</body>
</html>